package dmp.every;

import java.io.IOException;
import java.net.URLDecoder;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

public class GetEveryMapper extends Mapper<LongWritable, Text, Text, Text> {
	private Text resultKey=new Text();
	private Text resultValue=new Text();
	@Override
	protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
		String line=value.toString();
		String[] data=line.split("\\|");
		if(line.length()!=38){
			return;
		}
		String imsi = null;
		String sourceIP = null;
		String starttime = null;
		String endtime = null;
		String destinationURL = null;
		String domainName = null;
		
		imsi = data[0].trim();
		sourceIP=data[6].trim();
		starttime = data[17].length() > 10 ? data[17].trim().substring(0, 9) : "";
		endtime = data[18].length() > 10 ? data[18].trim().substring(0, 9) : "";
		destinationURL = URLDecoder.decode(data[27].trim().replaceAll("%(?![0-9a-fA-F]{2})", "%25"), "UTF-8");
		domainName = data[28].trim();
		
		resultKey.set(imsi+"|"+domainName);
		resultValue.set(sourceIP+"|"+starttime+"|"+endtime+"|"+destinationURL);
	}
}
